import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'
import allConstRoutes from './allConstRoutes'
export const constantRoutes = allConstRoutes

Vue.use(Router)

export const asyncRoutes = [ // 异步加载路由
  {
    path: '/goods',
    component: Layout,
    redirect: '/goods/goodsList',
    name: 'goods',
    meta: { title: '商品管理', icon: '路由嵌套' },
    children: [
      {
        path: '/goodsList',
        name: 'goodsList',
        component: () => import('@/views/goods/goodsList/index'),
        meta: { title: '商品列表', icon: '路由嵌套' }
      },
      {
        path: 'addGoods',
        component: () => import('@/views/goods/addGoods/index'),
        name: 'addGoods',
        meta: { title: '添加商品', icon: '路由嵌套' }
        // redirect: '/goods/addGoods'
        // children: [
        //   {
        //     path: 'menu1-1',
        //     component: () => import('@/views/nested/menu1/menu1-1'),
        //     name: 'Menu1-1',
        //     meta: { title: '选择商品分类', icon: '路由嵌套' }
        //   },
        //   {
        //     path: 'menu1-2',
        //     component: () => import('@/views/nested/menu1/menu1-2'),
        //     name: 'Menu1-2',
        //     redirect: '/nested/menu1/menu1-2/menu1-2-1',
        //     meta: { title: '填写商品信息', icon: '路由嵌套' },
        //     children: [
        //       {
        //         path: 'menu1-2-1',
        //         component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
        //         name: 'Menu1-2-1',
        //         meta: { title: '菜单 1-2-1', icon: '路由嵌套' }
        //       },
        //       {
        //         path: 'menu1-2-2',
        //         component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
        //         name: 'Menu1-2-2',
        //         meta: { title: '菜单 1-2-2', icon: '路由嵌套' }
        //       }
        //     ]
        //   },
        //   {
        //     path: 'menu1-3',
        //     component: () => import('@/views/nested/menu1/menu1-3'),
        //     name: 'Menu1-3',
        //     meta: { title: '菜单 1-3', icon: '路由嵌套' }
        //   }
        // ]
      },
      {
        path: 'goodsCate',
        name: 'goodsCate',
        component: () => import('@/views/goods/goodsCate/index'),
        meta: { title: '商品分类', icon: '路由嵌套' }
      },
      {
        path: 'brands',
        name: 'brands',
        component: () => import('@/views/goods/brands/index'),
        meta: { title: '品牌管理', icon: '路由嵌套' }
      },
      {
        path: 'Supplier',
        name: 'Supplier',
        component: () => import('@/views/goods/Supplier/index'),
        meta: { title: '供应商管理', icon: '路由嵌套' }
      },
      {
        path: 'banners',
        name: 'banners',
        component: () => import('@/views/goods/banners/index'),
        meta: { title: '轮播图管理', icon: '路由嵌套' }
      }
    ]
  },
  {
    path: '/orders',
    component: Layout,
    redirect: '/orders/ordersList',
    name: 'orders',
    meta: { title: '订单管理', icon: '路由嵌套' },
    children: [
      {
        path: '/ordersList',
        name: 'ordersList',
        component: () => import('@/views/orders/ordersList/index'),
        meta: { title: '订单列表', icon: '路由嵌套' }
      },
      {
        path: '/ordersSet',
        component: () => import('@/views/orders/ordersSet/index'),
        name: 'ordersSet',
        meta: { title: '订单设置', icon: '路由嵌套' }
      }
    ]
  },
  {
    path: '/returnGoods',
    component: Layout,
    redirect: '/returnGoods/returnGoodsList',
    name: 'returnGoods',
    meta: { title: '退货管理', icon: '路由嵌套' },
    children: [
      {
        path: '/returnGoodsList',
        name: 'returnGoodsList',
        component: () => import('@/views/returnGoods/returnGoodsList/index'),
        meta: { title: '退货申请', icon: '路由嵌套' }
      },
      {
        path: '/reasonSet',
        component: () => import('@/views/returnGoods/reasonSet/index'),
        name: 'reasonSet',
        meta: { title: '退款原因设置', icon: '路由嵌套' }
      }
    ]
  },
  {
    path: '/actives',
    component: Layout,
    redirect: '/actives/activesList',
    name: 'actives',
    meta: { title: '活动管理', icon: '路由嵌套' },
    children: [
      {
        path: '/activesList',
        name: 'activesList',
        component: () => import('@/views/actives/activesList/index'),
        meta: { title: '活动列表', icon: '路由嵌套' }
      },
      {
        path: '/adList',
        component: () => import('@/views/actives/adList/index'),
        name: 'adList',
        meta: { title: '广告管理', icon: '路由嵌套' }
      }
    ]
  },
  // {
  //   path: '/code-example',
  //   component: Layout,
  //   redirect: '/code-example',
  //   name: 'CodeExample',
  //   meta: { title: '开发示例', icon: '开发示例' },
  //   children: [
  //     {
  //       path: 'data-map',
  //       name: 'PageMap',
  //       component: () => import('@/views/NestedExample/PageDataMap'),
  //       meta: { title: '数据地图', icon: '中国地图' }
  //     },
  //     {
  //       path: 'query-search',
  //       component: () => import('@/views/NestedExample/PageQuerySearch'),
  //       name: 'PageQuerySearch',
  //       meta: { title: '条件查询', icon: '条件查询' }
  //     },
  //     {
  //       path: 'fast-chart',
  //       component: () => import('@/views/NestedExample/PageFastChart'),
  //       name: 'PageFastChart',
  //       meta: { title: '快速图表', icon: '快速图表' }
  //     },
  //     {
  //       path: 'button-permission',
  //       component: () => import('@/views/NestedExample/PageButtonPermission'),
  //       name: 'PageButtonPermission',
  //       meta: { title: '按钮权限', icon: '按钮权限', buttonPermission: [
  //         { id: 'search', name: '搜索', permission: true },
  //         { id: 'add', name: '添加', permission: true },
  //         { id: 'del', name: '删除', permission: true }
  //       ] }
  //     }
  //   ]
  // },
  {
    path: '/admin-manage',
    component: Layout,
    redirect: '/admin-manage/role-manage',
    name: 'AdminManage',
    meta: { title: '系统管理', icon: '后台管理' },
    children: [
      {
        path: 'account-manage',
        name: 'PageAccountManage',
        component: () => import('@/views/NestedAdminManage/PageAccountManage'),
        meta: { title: '用户管理', icon: '账号管理', noCache: true }
      },
      {
        path: 'role-manage',
        component: () => import('@/views/NestedAdminManage/PageRoleManage'),
        name: 'PageRoleManage',
        meta: { title: '角色管理', icon: '角色管理', noCache: true }
      }
    ]
  }
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  base: '/',
  routes: constantRoutes,
  mode: 'history'
})

const router = createRouter()

export function resetRouter() { // 重置路由
  router.matcher = createRouter().matcher
}

export default router
